package com.lele.create;

import java.io.IOException;
import java.util.List;

import com.lele.factory.AllFileFactory;
import com.lele.factory.AllJSFactory;
import com.lele.file.SpringConfigFile;
import com.lele.file.SuperFile;
import com.lele.js.ExtDesktopJS;
import com.lele.js.SuperJS;
import com.lele.util.FolderUtil;

public class CreateFile {
	public static void createFile(SuperFile sf) throws IOException{
		/**
		 * 生成java文件
		 */
		List<SuperFile> l = AllFileFactory.createFile(sf);
		String file_content = "";
		String file_url = "";
		for (int i = 0; i < l.size(); i++) {
			file_content = l.get(i).getContent();
			file_url = l.get(i).getFileURL();
			FolderUtil.createFile(file_url, file_content, "UTF-8");
		}
		/**
		 * 生成spring配置文件
		 */
		SpringConfigFile scf = new SpringConfigFile(sf);
		String[] config_url =  scf.getConfigURL();
		FolderUtil.createFile(config_url[0], scf.getActionsContent(), "UTF-8");
		FolderUtil.createFile(config_url[1], scf.getBeansContent(), "UTF-8");
		/**
		 * 生成js文件
		 */
		SuperJS sjs = new SuperJS();
		sjs.setEntityName(sf.getEntityName());
		sjs.setEntityClass(sf.getEntityClass());
		sjs.setProject_root(sf.getProject_root());
		sjs.setFields(sf.getFields());
		List<SuperJS> ljs = AllJSFactory.createFile(sjs);
		for (int i = 0; i < ljs.size(); i++) {
			file_content = ljs.get(i).getContent();
			file_url = ljs.get(i).getFileURL();
			FolderUtil.createFile(file_url, file_content, "UTF-8");
		}
		/**
		 * 生成extjs桌面图标文件
		 */
		ExtDesktopJS js = new ExtDesktopJS(sjs);
		FolderUtil.createFile(js.getFileURL(), js.getContent(), "UTF-8");
	}
	public static void main(String[] args) {
		/*SuperJS sjs = new SuperJS();
		sjs.setEntityName("requirement");
		sjs.setEntityClass("Requirement");
		sjs.setProject_root("E:\\Workspaces\\");
		ExtDesktopJS js = new ExtDesktopJS(sjs);
		try {
			FolderUtil.createFile(js.getFileURL(), js.getContent(), "UTF-8");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
	}
}
